import java.util.Arrays;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2021-08-03
 * Time:15:10
 */
class TestDemo2{
    public int a;
    public static int count;
    public static void change() {
        count = 100;
       // a = 10;// error 不可以访问非静态数据成员
    }
}
class Person{
    private String name;//实例成员变量
    private int age;
    private String sex;
    private static int count = 0;//静态成员变量 由类共享数据 方法区
    public Person(){
        System.out.println("I am Person init()!");
    }
    //实例代码块
    {
        this.name = "bit";
        this.age = 12;
        this.sex = "man";
        System.out.println("I am instance init()!");
    }
    //静态代码块
    static {
        count = 10;//只能访问静态数据成员
        System.out.println("I am static init()!");
    }
    public void show(){
        System.out.println("name: "+name+" age: "+age+" sex: "+sex);
    }
}
class TestDemo1{
    public int a;
    public static int count;
}
public class TestDemo {
    public static void main(String[] args) {
        Person p1 = new Person();
        Person p2 = new Person();//静态代码块是否还会被	执行？
    }
    public static void main5(String[] args) {
        TestDemo2.change();//无需创建实例对象 就可以调用
        System.out.println(TestDemo2.count);
    }
    public static void main4(String[] args) {
        TestDemo1 t1 = new TestDemo1();
        t1.a++;
        t1.count++;
        System.out.println(t1.a);
        System.out.println(t1.count);
        System.out.println("============");
        TestDemo1 t2 = new TestDemo1();
        t2.a++;
        t2.count++;
        System.out.println(t2.a);
        System.out.println(t2.count);
    }
    public static void main3(String[] args) {
        TestDemo1 t1 = new TestDemo1();
        t1.a++;
        TestDemo1.count++;
        System.out.println(t1.a);
        System.out.println(TestDemo1.count);
        System.out.println("============");
        TestDemo1 t2 = new TestDemo1();
        t2.a++;
        TestDemo1.count++;
        System.out.println(t2.a);
        System.out.println(TestDemo1.count);
    }

    /**
     * 给定两个整型数组, 交换两个数组的内容.
     * @param args
     */
    public static void main2(String[] args) {
        int[] array1 = {1,3,5,7,9};
        int[] array2 = {0,2,4,6,8};
        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));
        swapArray(array1,array2);
        System.out.println("===============================");
        System.out.println(Arrays.toString(array1));
        System.out.println(Arrays.toString(array2));
     }
     public static void swapArray(int[] array1,int[] array2) {
         for (int i = 0; i < array2.length; i++) {
             int tmp = array1[i];
             array1[i] = array2[i];
             array2[i] = tmp;
         }
     }
    /**
     *     给定整型数组, 把所有的偶数放到数组前面, 把所有奇数放到数组后面.
     * @param args
     */
    public static void main1(String[] args) {
        int[] array = {1,2,3,4,5,6,7,8,9};
        func1(array);
        System.out.println(Arrays.toString(array));
    }
    public static void func1(int[] array) {
        int left = 0;
        int right = array.length - 1;
        while(left < right) {
            while (left < right && array[left] %2 != 1) {
                left ++;
            }
            while (left < right && array[right] %2 != 0) {
                right--;
            }
            int tmp = array[left];
            array[left] = array[right];
            array[right] = tmp;
        }
    }
}
